package cliente.servico;

import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;


@SuppressWarnings("serial")
public class ProcurarServicos extends AbstractAction{

	private Action buscaServico;
	
	private JFrame tfBuscarServicos;
	private JLabel servicoId;
	private JTextField servidoIdText;
	private JLabel descricao;
	private JTextField descticaoText;
	private JLabel preco;
	private JFormattedTextField precoText;
	private JButton procurar;
	private JButton alterar;
	private JButton apagar;
	private JButton fechar;
	
	public ProcurarServicos() {
		// Nome da ação
		super(" Procurar Serviços");
		
		buscaServico = new AcoesProcurarServicos(this);
		
		this.putValue(Action.SHORT_DESCRIPTION, "Busca serviços cadastrados");
	}
	
	// Define o que será executado quando a ação for acionada
	public void actionPerformed(ActionEvent ev){
		tfBuscarServicos = new JFrame("Buscar Servicos");
		tfBuscarServicos.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
		
		Container interno = tfBuscarServicos.getContentPane();
		GridBagConstraints cons = new GridBagConstraints();
		GridBagLayout layout = new GridBagLayout();
		interno.setLayout(layout);
		
		cons.insets = new Insets(2,2,2,2);
		
		// Componentes da tela
		servicoId = new JLabel("Id");
		cons.weightx = 0.25;
		cons.fill = GridBagConstraints.NONE;
		cons.gridx = 0;
		cons.gridy = 0;
		interno.add(servicoId,cons);
		
		servidoIdText = new JTextField();
		cons.weightx = 0.75;
		cons.gridx = 1;
		cons.gridy = 0;
		cons.fill = GridBagConstraints.HORIZONTAL;
		interno.add(servidoIdText, cons);
		
		descricao = new JLabel("Descricao");
		cons.weightx = 0.25; 
		cons.gridx = 0;
		cons.gridy = 1;
		cons.fill = GridBagConstraints.NONE;
		interno.add(descricao,cons);
		
		descticaoText = new JTextField();
		cons.weightx = 0.75;
		cons.gridx = 1;
		cons.gridy = 1;
		cons.fill = GridBagConstraints.HORIZONTAL;
		interno.add(descticaoText,cons);
		
		preco = new JLabel("Preço");
		cons.weightx = 0.25;
		cons.gridx = 0;
		cons.gridy = 2;
		cons.fill = GridBagConstraints.NONE;
		interno.add(preco, cons);
		
		precoText = new JFormattedTextField();
		cons.weightx = 0.25;
		cons.gridx = 1;
		cons.gridy = 2;
		cons.fill = GridBagConstraints.HORIZONTAL;
		interno.add(precoText, cons);
		
		procurar = new JButton("Procurar");
		cons.weightx = 0.5;
		cons.gridx = 0;
		cons.gridy = 3;
		cons.fill = GridBagConstraints.NONE ;
		interno.add(procurar, cons);
		procurar.setActionCommand("procurar");
		procurar.addActionListener(getBuscaServico());
		
		alterar = new JButton("Alterar");
		cons.weightx = 0.5;
		cons.gridx = 1;
		cons.gridy = 3;
		interno.add(alterar, cons);
		alterar.setActionCommand("alterar");
		alterar.addActionListener(getBuscaServico());
		
		apagar = new JButton("Apagar");
		cons.weightx = 0.5;
		cons.gridx = 0;
		cons.gridy = 4;
		cons.fill = GridBagConstraints.NONE ;
		interno.add(apagar, cons);
		apagar.setActionCommand("apagar");
		apagar.addActionListener(getBuscaServico());
		
		fechar = new JButton("Fechar");
		cons.weightx = 0.5;
		cons.gridx = 1;
		cons.gridy = 4;
		interno.add(fechar, cons);
		fechar.setActionCommand("fecha");
		fechar.addActionListener(getBuscaServico());
		
		tfBuscarServicos.setSize(300,200);
		tfBuscarServicos.setVisible(true);
	}

	public Action getBuscaServico() {
		return buscaServico;
	}

	public void setBuscaServico(Action buscaServico) {
		this.buscaServico = buscaServico;
	}

	public JLabel getServicoId() {
		return servicoId;
	}

	public void setServicoId(JLabel servicoId) {
		this.servicoId = servicoId;
	}

	public JTextField getServidoIdText() {
		return servidoIdText;
	}

	public void setServidoIdText(JTextField servidoIdText) {
		this.servidoIdText = servidoIdText;
	}

	public JLabel getDescricao() {
		return descricao;
	}

	public void setDescricao(JLabel descricao) {
		this.descricao = descricao;
	}

	public JTextField getDescticaoText() {
		return descticaoText;
	}

	public void setDescticaoText(JTextField descticaoText) {
		this.descticaoText = descticaoText;
	}

	public JLabel getPreco() {
		return preco;
	}

	public void setPreco(JLabel preco) {
		this.preco = preco;
	}

	public JFormattedTextField getPrecoText() {
		return precoText;
	}

	public void setPrecoText(JFormattedTextField precoText) {
		this.precoText = precoText;
	}

	public JButton getProcurar() {
		return procurar;
	}

	public void setProcurar(JButton procurar) {
		this.procurar = procurar;
	}

	public JButton getFechar() {
		return fechar;
	}

	public void setFechar(JButton fechar) {
		this.fechar = fechar;
	}

	public void setTfBuscarServicos(JFrame tfBuscarServicos) {
		this.tfBuscarServicos = tfBuscarServicos;
	}

	public JFrame getTfBuscarServicos() {
		return tfBuscarServicos;
	}

	public void setAlterar(JButton alterar) {
		this.alterar = alterar;
	}

	public JButton getAlterar() {
		return alterar;
	}

	public void setApagar(JButton apagar) {
		this.apagar = apagar;
	}

	public JButton getApagar() {
		return apagar;
	}
}


